<?php
// +----------------------------------------------------------------------------
// | Tke团队版权所属 [三十年河东三十年河西,莫欺少年穷.!]
// +----------------------------------------------------------------------------
// | Copyright (c) 2014 http://www.itdaodan.com All rights reserved.
// +----------------------------------------------------------------------------
// | Author: nengwan_03@163.com
// +----------------------------------------------------------------------------
/**
 +------------------------------------------------------------------------------
 * 动态模型
 +------------------------------------------------------------------------------
 * @version   1.0
 * @since 2014-10-14
 +------------------------------------------------------------------------------
 */
namespace Home\Model;
use Think\Model;

class GuanModel extends Model {
	
	
	private $request_key = request_key;//密钥
	private $request_title = request_title;//名称
	private $url = url;
	//'http://192.168.1.170/open_trends/Index/';
	//接口地址//'http://open-event.embayun.com/Index/';
	private $handel = '';
	

	//获取相应人的学校和学届信息
	public function dreamLogin($phone,$pwd){
		if(empty($phone) || empty($pwd)){
			return false;
		}
		$data = array('action'=>'loginUser');
		$data['user_login'] = $phone;
		$data['user_pwd'] = $pwd;
// dump($data);die;
		$data_from = $this->pushData($this->callBackByAes($data));
		return $data_from;
	}

	//获取用户信息
	public function dreamUserInfo($id){
		$data = array('action'=>'dreamUserInfo');
		$data['user_id'] = $id;
		$data_from = $this->pushData($this->callBackByAes($data));
		return $data_from;
	}
	
	//获取用户学校信息
	public function dreamUserList($ids){
		$data = array('action'=>'dreamUserList');
		$data['user_ids'] = $ids;
		$data_from = $this->pushData($this->callBackByAes($data));
		return $data_from;
	}
	
	/**
	 * @todo 请求接口
	 */
	private function pushData(&$json_data){
		import('Common.Org.Msj.Curl');
		$curl =  new \Curl();
		return $this->deData($curl->curl_post($this->url,array('para'=>$json_data)));
	}
	
	/**
	 * @todo 获取验证码接口
	 */
	public function zcGetVerifyCode($phone){
		$data = array('action'=>'zcGetVerifyCode');
		$data['phone'] = $phone;
		$data_from = $this->pushData($this->callBackByAes($data));
		return $data_from;
	}
	
	/**
	 * @todo 解密接口
	 */
	private function deData(&$json_data){
		if(!is_object($this->handel)){
			import('Org.Util.Aes','','.php');
			$this->handel	=	new \Aes();
		}
		return json_decode ( urldecode ( $this->handel->siyuan_aes_decode ( str_replace ( " ", "+", $json_data ) ) ), true );
	}
	
	/**
	 * @todo	生成经过Aes加密后的字符串
	 * @param  array $json_data
	 * @return string
	 * @Author: PHP@妖孽 <dino_ma@163.com>
	 *
	 *
	 * @example
	 * success::
	 * array(
	 *    'status'=>1,
	 *    'data'=>array(),
	 *   )
	 *
	 * error:
	 * array(
	 * 	'status'=>0,
	 * 	'info'=>'错误提示信息',
	 * )
	 */
	private function callBackByAes(&$return_data){

		if(!is_object($this->handel)){
			import('Common.Org.Util.Aes','','.php');
			$this->handel	=	new \Aes();
		}
		$return_data['request_key'] = $this->request_key;
		$return_data['request_title'] = $this->request_title;
		$return_data['key'] = data_auth_sign($return_data);
// dump($this->handel->siyuan_aes_encode(urldecode(json_encode( $return_data ))));die;
		return str_replace('"','',$this->handel->siyuan_aes_encode(urldecode(json_encode( $return_data ))));
	}
}